package com.tang.lts.remoting.protocol;


import com.tang.lts.remoting.protocol.command.RemoteCommandBody;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Tang
 * @classname RemoteCommand
 * @description [ remoting 模块下面的 ]
 * @date 2022/5/26 16:25
 */
public class RemoteCommand implements Serializable {

    private static final AtomicInteger requestId = new AtomicInteger(0);

    private int code;
    private int subCode;
    private int opaque;

    private String remark;

    RemoteCommandBody commandBody;

    public static RemoteCommand createRequestCommand(int code, RemoteCommandBody body) {
        RemoteCommand remoteCommand = new RemoteCommand();
        remoteCommand.setCode(code);
        remoteCommand.setCommandBody(body);
        remoteCommand.setOpaque(requestId.incrementAndGet());
        return remoteCommand;
    }

    public static RemoteCommand createRequestCommand(int code,String remark, RemoteCommandBody body) {
        RemoteCommand remoteCommand = new RemoteCommand();
        remoteCommand.setCode(code);
        remoteCommand.setCommandBody(body);
        remoteCommand.setRemark(remark);
        remoteCommand.setOpaque(requestId.incrementAndGet());
        return remoteCommand;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public int getOpaque() {
        return opaque;
    }

    public void setOpaque(int opaque) {
        this.opaque = opaque;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getSubCode() {
        return subCode;
    }

    public void setSubCode(int subCode) {
        this.subCode = subCode;
    }

    public RemoteCommandBody getCommandBody() {
        return commandBody;
    }

    public void setCommandBody(RemoteCommandBody commandBody) {
        this.commandBody = commandBody;
    }
}